<!DOCTYPE HTML>
<html lang="cn" xmlns="http://www.w3.org/1999/xhtml">
<head>
    <%include("/common/header.html",{title:''}){}%>
    <title>增值服务</title>
</head>
<script type="text/javascript" src="//api.map.baidu.com/api?v=2.0&ak=IENn7ABARjQIkTeAKyh80VTkg2jYXf3K"></script>
<style>
    .layui-upload-img {
        width: 92px;
        height: 92px;
        margin: 0 10px 10px 0;
    }
</style>
<body>

<div class="x-nav" style="margin: 20px auto auto 15px;">
      <span class="layui-breadcrumb" lay-filter="breadcrumb" style="visibility: visible;">
        <a href="javascript:">首页</a><span lay-separator="">/</span>
        <a href="javascript:">系统设置</a><span lay-separator="">/</span>
        <a><cite>增值服务</cite></a>
      </span>
    <a class="layui-btn layui-btn-primary layui-btn-small" style="margin: -5px 14px 0px 0px;float:right;"
       href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon layui-icon-refresh-3"></i>
    </a>
</div>
<div class="x-body" style="margin: 20px auto auto 15px;">

    <div class="layui-row">
        <div class="layui-input-inline">
            <input type="text" id="search_term" placeholder="请输入服务名称" autocomplete="off" class="layui-input">
        </div>
        <div class="layui-input-inline">
            <button class="layui-btn layui-btn-checked" lay-submit="" lay-filter="sreach" id="searchBtn"><i
                    class="layui-icon layui-icon-search"></i>查询
            </button>
        </div>
    </div>
</div>
<div class="layui-fluid">
    <div class="layui-card">
        <table id="LAY-user-manage" lay-filter="LAY-user-manage"></table>
        <script type="text/html" id="toolbarDemo">
            <a class="layui-btn layui-btn layui-btn-sm" lay-event="add"><i class="layui-icon layui-icon-add-1"></i>添加增值服务</a>
        </script>
        <script type="text/html" id="table-useradmin-webuser">
            <a class="layui-btn  layui-btn-xs" lay-event="detail"><i class="layui-icon layui-icon-form"></i>查看</a>
            <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i
                    class="layui-icon layui-icon-close"></i>删除</a>
        </script>
    </div>
</div>

<!--查看巡查台账内容-->
<div class="layui-form" lay-filter="layuiadmin-form-useradmin"
     id="layuiadmin-form-useradmin"
     style="padding: 15px;display: none">
    <form action class="layui-form" lay-filter="component-form-element" id="myform">
        <input type="hidden" name="id">
        <div class="layui-form-item">
            <label class="layui-form-label">*服务名称:</label>
            <div class="layui-input-inline">
                <input type="text" name="serviceName" id="serviceName" lay-filter="serviceName" class="layui-input" placeholder="请输入服务名称">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">*服务金额:</label>
            <div class="layui-input-inline">
                <input type="text" name="pice" id="pice" lay-filter="payMoney" placeholder="请输入服务金额" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">*返佣金额:</label>
            <div class="layui-input-inline">
                <input type="text" name="reward" id="reward" lay-filter="payMoney" placeholder="请输入服务金额" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item" id="time">
            <label class="layui-form-label">*创建时间:</label>
            <div class="layui-input-inline">
                <input type="text" readonly name="createTime" id="createTime" lay-filter="createTime"
                       class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit="" id="lay-submit" lay-filter="component-form-element">立即提交
                </button>
            </div>
        </div>
    </form>
</div>
<script type="text/html" id="xuhao">
    {{d.LAY_TABLE_INDEX+1}}
</script>
<%include("/common/foot.html"){}%>

<script>
    layui.use(['index', 'table', 'jquery', 'form','util', 'upload', 'laydate', 'layedit', 'AjaxCommon', 'AliangLayui'], function () {
        var $ = layui.$;
        var table = layui.table;
        var form = layui.form;
        var laydate = layui.laydate;
        var AjaxCommon = layui.AjaxCommon;
        var AliangLayui = layui.AliangLayui;
        var util=layui.util;
        var upload = layui.upload;
        var title = "增值服务管理";
        var findAll_url = 'info/getAll.json;';
        var saveOrUpdata_url = "addservice/list/update.jhtml";
        var delete_url = "addservice/list/delete.jhtml";
        var index;//定义建立富文本编辑器全局变量
        var layedit;//定义富文本编辑器layedit全局变量

        var cols = [ //表头
            {field: 'serviceName', sort: 'true', title: '服务名称', align: 'center'},
            {field: 'pice', sort: 'true', title: '金额', align: 'center'},
            {field: 'reward', sort: 'true', title: '返佣', align: 'center'},
            {
                field: 'beginTime',
                sort: 'true',
                title: '添加时间',
                align: 'center',
                templet: "<div>{{layui.util.toDateString(d.beginTime, 'yyyy-MM-dd ')}}</div>"
            },
            {title: '操作', fixed: 'right', width: 215, toolbar: '#table-useradmin-webuser'}
        ];



        //头工具栏事件 添加巡查台账
        table.on('toolbar(LAY-user-manage)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id);
            switch (obj.event) {
                case 'add':
                    initUpdate(0);
                    break;
                case 'delete':
                    var data = checkStatus.data;
                    break;
                case 'export':
                    layer.msg("导出");
                    break;
            }
        });

        function initUpdate(data) {
            layer.open({
                type: 1,
                title: title,
                area: ['400px', '300px'],
                content: $('#layuiadmin-form-useradmin'),
                //可以无限个按钮
                cancel: function (index, layero) {//取消事件
                    location.replace(location.href);　//layer.open关闭刷新
                },
                success: function (layero, index) {
                    layer.iframeAuto(index);
                }
            });
            if (data == 0 || data == null) {
                $('#myform')[0].reset();
                $("#time").hide()
                return;
            } else {
                layui.form.val("component-form-element", loadData(data));
            }
        }
        laydit = layui.layedit;
        form.verify({
            introduce: function (value) {
                var val = layedit.getText(index);
                //alert(val.length)
                if (val.length < 6) {
                    return '内容至少6个字符'
                }
            }
        });
        //加载查看数据
        function loadData(data) {
            console.log(JSON.stringify(data));
            var ret = {
                "id": data.id,
                "serviceName": data.serviceName,
                "reward":data.reward,
                "pice": data.pice,
                "createTime":layui.util.toDateString(data.createTime)
            }
            // form.render();
            return ret;
        }

        form.on('submit(component-form-element)', function (data) {
            // alert(JSON.stringify(data.field));
            postUpdate(data.field);
            return false;
        });


        //渲染表格
        AliangLayui.createTable(
            "#LAY-user-manage",
            "listReload",
            "#toolbarDemo",
            title,
            'addservice/list/find.jhtml',
            true,
            [10, 15, 20, 25],
            ['filter', 'print', 'exports'],
            cols
        );

        //搜索栏
        var keyWord;
        var keyWordTwo;
        var state;
        var receiver;
        $('#searchBtn').on('click', function () {
            //按施工方搜索
            receiver = $("#receiver").val();
            //按任务状态搜索
            state = $("#state").val();
            //任务名称搜索
            keyWord = $("#searchSource").val();
            //问题情况搜索
            keyWordTwo = $('#search_term').val();
            table.reload('listReload', {
                url: findAll_url,
                where: {
                    keyWord: keyWord,
                    keyWordTwo: keyWordTwo,
                    state: state,
                    receiver: receiver
                },
                page: {
                    curr: 1//重新从第 1 页开始
                }
            });
        });


        table.on('tool(LAY-user-manage)', function (obj) {
            var data = obj.data;
            if (obj.event === 'detail') {
                initUpdate(data);
            } else if (obj.event === 'del') {
                layer.confirm('删除信息之后，信息不再显示！', function (index) {
                    postDelete(data.id);
                });
            }
        });

        window.postUpdate = function (data) {
            var formData = new FormData();
            formData.append("data", JSON.stringify(data));
            $.ajax({
                url: saveOrUpdata_url,//发送添加巡查台账的信息
                type: "post",
                data: formData,
                processData: false,
                contentType: false,
                success: function (data) {
                    if (data.code === 0) {
                        layer.closeAll();
                        layer.msg(data.msg, {
                            time: 600,
                            icon: 1
                        }, function () {
                            location.replace(location.href);
                        })
                    } else {
                        layer.msg(data.msg, {
                            icon: 5
                        })
                    }
                },
                error: function (jqXHR, textStatus, errorThrown) {
                    var esta = "Page:" + window.location.pathname + ",Function:postUpdate()";
                    layer.open({
                        title: "错误信息",
                        type: 2,
                        content: "base/error.jhtml?info=" + esta,
                        btn: ['关闭']
                    })
                }
            })
        };


        window.postDelete = function (id) {
            AjaxCommon.ajax(delete_url, "post", "json", {"id": id}, function (ret) {
                if (ret == null) {
                    layer.msg("删除失败", {
                        icon: 5
                    });
                } else {
                    layer.msg(ret.msg, {time: 600, icon: 6}, function () {
                        location.replace(location.href);
                    });
                    layer.closeAll();
                }
                return ret;
            });
        };
    });
</script>


</body>

</html>
